<template>
  <div class="usersmanage-container">
    <breadcrumb style="position: absolute;width:100%;"></breadcrumb>
    <div class="content">
      <div class="query">
        <div class="btn">
          <el-button type="primary" @click="$router.go(-1)">返回</el-button>
        </div>
      </div>
      <div class="table">
        <el-table :data="usersList" style="width: 100%" height="598">
          <el-table-column prop="userNomber" label="用户ID"></el-table-column>
          <el-table-column prop="userName" label="用户昵称"></el-table-column>
          <el-table-column prop="balance" label="实际消费金额（元）"></el-table-column>
          <el-table-column prop="orderNo" label="订单号"></el-table-column>
          <el-table-column prop="orderCreatetime" label="下单时间"></el-table-column>
        </el-table>
        <pagination
          :currentPage="currentPage"
          :page="page"
          :total="total"
          :pageSize="pageSize"
          @change-current="currentChange"
          @change-size="sizeChange"
        ></pagination>
      </div>
    </div>
  </div>
</template>

<script>
import breadcrumb from "../../components/breadcrumb";
import pagination from "../../components/page";

export default {
  components: { breadcrumb, pagination },
  data() {
    return {
      id: this.$route.query.id,
      currentPage: 1,
      pageSize: 10,
      usersList: [],
      total: 0,
      value: "",
      value1: "",
      value2: "",
      value3: "",
      page: 1
    };
  },
  created() {
    if (localStorage.getItem("pageMsg")) {
      let pageMsg = JSON.parse(localStorage.getItem("pageMsg"));

      this.currentPage = pageMsg.currentPage;
      this.pageSize = pageMsg.pageSize;
      localStorage.removeItem("pageMsg");
    }
    this.get_usersList();
  },
  methods: {
    sizeChange(val) {
      this.pageSize = val;
      this.currentPage = 1;
      this.get_usersList();
    },
    currentChange(val) {
      this.currentPage = val;
      this.get_usersList();
    },
    get_usersList() {
      this.usersList = [];
      var data =
        "current=" +
        this.currentPage +
        "&size=" +
        this.pageSize +
        "&amountNumber=" +
        this.id;
      this.$axios
        .post("/web_userteam/select_amount_inviter", data)
        .then(result => {
          if (result.data.status == 0) {
            this.total = result.data.data.total;
            this.page = Math.ceil(result.data.data.total / this.pageSize);
            this.usersList = result.data.data.records;
          }
        });
    },
    handleForbidden(status, id) {
      this.$confirm("此操作将修改状态, 是否继续?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      })
        .then(() => {
          this.$axios
            .post("/web_user/modify_status", "id=" + id)
            .then(result => {
              //console.log(result, "状态");
              if (result.data.status == 0) {
                if (result.data.data == 1) {
                  if (status == "冻结") {
                    this.$message({
                      type: "success",
                      message: "启用成功"
                    });
                  } else {
                    this.$message({
                      type: "success",
                      message: "冻结成功"
                    });
                  }
                  this.usersList.forEach(item => {
                    if (item.id == id) {
                      item.status = item.status == "冻结" ? "正常" : "冻结";
                    }
                  });
                } else {
                  return this.$message({
                    type: "warning",
                    message: "修改失败"
                  });
                }
              }
            });
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消修改"
          });
        });
    }
  }
};
</script>


<style lang="less" >
.usersmanage-container {
  @import "../../style/table.less";
  @import "../../style/content.less";
  display: flex;
  flex-flow: column;
  position: relative;
  height: 100%;
  .el-table .cell {
    white-space: pre-line !important;
  }
}
</style>
